package com.zhoug.zmuidemo.ui;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.OrientationHelper;
import androidx.recyclerview.widget.RecyclerView;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.zhoug.common.adapters.recycler.BaseRecyclerViewAdapter;
import com.zhoug.common.adapters.recycler.BaseViewHolder;
import com.zhoug.common.adapters.recycler.dividers.ListItemDecoration;
import com.zhoug.zmui.marquee.ZMUIAutoScrollListView;
import com.zhoug.zmui.marquee.ZMUIMarqueeHorizontalTextView;
import com.zhoug.zmuidemo.R;

import java.util.Arrays;

public class MarqueeActivity extends AppCompatActivity {

    private ZMUIAutoScrollListView mScrollView;
    private ZMUIMarqueeHorizontalTextView mMarquee1;
    private ZMUIMarqueeHorizontalTextView mMarquee2;
    private ZMUIMarqueeHorizontalTextView mMarquee3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_marquee);
        findViews();

        Adapter adapter=new Adapter();
        adapter.setData(Arrays.asList("11111111","222222","3333333","4444444","55555555","666666","7777777777","888888","99999"));
        mScrollView.setLayoutManager(new LinearLayoutManager(this));
        mScrollView.addItemDecoration(new ListItemDecoration(this, OrientationHelper.VERTICAL));
        mScrollView.setAdapter(adapter);



    }

    private void findViews() {
        mScrollView = findViewById(R.id.scrollView);
        mMarquee1 = findViewById(R.id.marquee1);
        mMarquee2 = findViewById(R.id.marquee2);
        mMarquee3 = findViewById(R.id.marquee3);
    }

    public void start(View view) {
        mScrollView.start();
        mMarquee1.start();
        mMarquee2.start();
        mMarquee3.start();
    }

    public void stop(View view) {
        mScrollView.stop();
        mMarquee1.stop();
        mMarquee2.stop();
        mMarquee3.stop();
    }

    private class  Adapter extends ZMUIAutoScrollListView.Adapter<String>{

        @Override
        public int getLayoutId(int viewType) {
            return R.layout.layout_text_item;
        }

        @Override
        public void onBindData(BaseViewHolder holder, String data, int position, int viewType) {
            ((TextView)  holder.itemView.findViewById(R.id.text)).setText(data);
            holder.itemView.setBackgroundColor(Color.parseColor("#cccccc"));
            holder.itemView.setOnClickListener(v->{
                Toast.makeText(MarqueeActivity.this, data, Toast.LENGTH_SHORT).show();
            });
        }

    }

    @Override
    protected void onResume() {
        super.onResume();
        start(null);
    }

    @Override
    protected void onPause() {
        super.onPause();
        stop(null);
    }
}